/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.camel.quickfix;

import org.apache.log4j.Logger;
import quickfix.*;

/**
 * QuickfixApplication is the root for application logic.
 *
 * @author Anton Arhipov
 * @see quickfix.Application
 */
public class QuickfixApplication implements Application {

  private static final Logger log = Logger.getLogger(QuickfixApplication.class);

  private QuickfixEndpoint endpoint;

  public QuickfixApplication(QuickfixEndpoint endpoint) {
    this.endpoint = endpoint;
  }

  public QuickfixEndpoint getEndpoint() {
    return endpoint;
  }

  public void setEndpoint(QuickfixEndpoint endpoint) {
    this.endpoint = endpoint;
  }

  public void onCreate(SessionID sessionID) {
    endpoint.setSessionID(sessionID);
  }

  public void onLogon(SessionID sessionID) {
    endpoint.setSessionID(sessionID);
  }

  public void onLogout(SessionID sessionID) {
    log.debug("logging out from session " + sessionID);
  }

  public void toAdmin(Message message, SessionID sessionID) {
    log.debug("to admin: [" + sessionID + "]: " + message);
  }

  public void fromAdmin(Message message, SessionID sessionID) throws FieldNotFound, IncorrectDataFormat, IncorrectTagValue, RejectLogon {
    log.debug("to admin: [" + sessionID + "]: " + message);
  }

  public void toApp(Message message, SessionID sessionID) throws DoNotSend {
    log.debug("to app: [" + sessionID + "]: " + message);
  }

  public void fromApp(Message message, SessionID sessionID) throws FieldNotFound, IncorrectDataFormat, IncorrectTagValue, UnsupportedMessageType {
    log.debug("from app: [" + sessionID + "]: " + message);
    endpoint.onMessage(message);
  }
}
